using System;
using Glue;
using Glue.Internals.Verification;
using GlueTests.Builders;
using Xunit;

namespace GlueTests.RelationsVerificationTests
{
    public class When_ignoring_a_property
    {
        private readonly RelationsVerification<DomainPerson, GuiPerson> relationsVerification;
        private readonly Mapping<DomainPerson, GuiPerson> mapping;

        public class DomainPerson
        {
            public String FirstName { get; set; }
            public String LastName { get; set; }
        }

        public class GuiPerson
        {
            public String FirstName { get; set; }
            public String LastName { get; set; }
        }

        public class WrongType { public String SomeProperty { get; set; } }

        public When_ignoring_a_property()
        {
            mapping = new Mapping<DomainPerson, GuiPerson>();
            mapping.Relate(domain=>domain.FirstName,gui=>gui.FirstName);
            relationsVerification = new RelationsVerification<DomainPerson, GuiPerson>(mapping, new ObjectMemberFactoryBuilder().Build());
        }

        [Fact]
        public void Should_verify_all_PropertiesRelated_when_ignoring_unrelated_on_LeftSide()
        {
            mapping.IgnoreTowards<DomainPerson>(x => x.LastName);
            relationsVerification.AssertAllPropertiesRelated<DomainPerson>();
            Assert.Throws(typeof(GlueException),()=> relationsVerification.AssertAllPropertiesRelated<GuiPerson>());
        }

        [Fact]
        public void Should_verify_all_PropertiesRelated_when_ignoring_unrelated_on_RightSide()
        {
            mapping.IgnoreTowards<GuiPerson>(x => x.LastName);
            relationsVerification.AssertAllPropertiesRelated<GuiPerson>();
            Assert.Throws(typeof(GlueException), () => relationsVerification.AssertAllPropertiesRelated<DomainPerson>());
        }

        [Fact]
        public void Should_throw_exception_when_type_is_not_LeftSide_or_RightSide()
        {
            Assert.Throws(typeof(GlueException), () => mapping.IgnoreTowards<WrongType>(x => x.SomeProperty));
        }
    }
}